import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

service = Service(executable_path='D:\\chromedriver.exe')
driver = webdriver.Chrome(service=service)
driver.maximize_window()

driver.get('http://127.0.0.1:5500/v_%E8%87%AA%E5%8A%A8%E5%8C%96/a_selenium/swith%E6%B5%8B%E8%AF%95%E6%A1%88%E4%BE%8B.html')


# 切换 进入 iframe
iframe = driver.find_element(By.XPATH, '//iframe')
driver.switch_to.frame(iframe)

# 在iframe中找btn
btn = driver.find_element(By.XPATH, "//button")
btn.click()


time.sleep(1)
driver.switch_to.alert.accept()

print(driver.window_handles)


# 切换回原始window
driver.switch_to.window(driver.window_handles[0])
time.sleep(1)
b = driver.find_element(By.XPATH, '//b')
print(b.text)



input()
driver.quit()